package model

import (
	"github.com/jjl309/oneGroup"
	"gorm.io/gorm"
)

type Order struct {
	gorm.Model
	OrderId     string  `gorm:"column:order_id;type:varchar(50);not null" json:"order_id"`
	FreshFoodId int     `gorm:"column:fresh_food_id;type:int;not null" json:"fresh_food_id"`
	Num         int     `gorm:"column:num;type:int;not null" json:"num"`
	TotalPrice  float64 `gorm:"column:total_price;type:int;not null" json:"total_price"`
	Status      int     `gorm:"column:status;type:int;not null;default:0" json:"status"`
	UserId      int     `gorm:"column:user_id;type:int;not null" json:"user_id"`
}

func (o *Order) TableName() string {
	return "order"
}
func (o *Order) Create() error {
	return oneGroup.DB.Create(&o).Error
}
func (o *Order) GetAllOrder() ([]Order, error) {
	var orders []Order
	err := oneGroup.DB.Find(&orders).Error
	return orders, err
}
